<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	

</head>
<body>

	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" >
        <div class="row" id="test01">
            <div >
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>回收物品管理</h5>

                    </div>
                    <div class="ibox-content">
                        <form action="${path}/regenerant/query" method="post" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label  class="sr-only">类型</label>
                                <select class="form-control" id="type" name="type">
                                    <option value="0">PET瓶</option>
                                    <option value="1">PE瓶</option>
                                    <option value="2">泡沫</option>
                                    <option value="3">硬质塑料</option>
                                    <option value="4">塑料袋膜</option>
                                    <option value="5">织物</option>
                                    <option value="6">玻璃</option>
                                    <option value="7">复合</option>
                                    <option value="8">电子电器</option>
                                    <option value="9">书报</option>
                                    <option value="10">综合纸</option>
                                    <option value="11">金属</option>
                                    <option value="12">铝拉罐</option>
                                    <option value="13">黄纸板</option>
                                </select>

                            </div>
                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-add-type" class="btn btn-success fr" style="margin-left: 10px">添加类型</button>
                            <button type="button" id="btn-add" class="btn btn-success fr">添加物品</button>
                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">


        $(document).ready(function () {

            var types = [];

            $.ajax({
                url:'${path}/regenerant/gettypes',
                type:'GET',
                dataType:'json',
                success:function(json){
                    types = json;
                }
            });


            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
            	url : "${path}/regenerant/queryC",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                   	id: "id", //相当于设置主键
		           	root: "result",//Json数据
		           	total: "allPage",//总页数
					page: "page", //当前页
					records: "allCount",//总记录数
					repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 30],
                colNames: ['类型','名称', '价格   kg/元(RMB)', ' 添加时间',  '说明','性质','操作'],
                colModel: [{
                        name: 'type',
                        index: 'type',
                        width: 20,
                    formatter:function(cellvalue, options, rowObject){

                        if (rowObject.typeA!='' && rowObject.typeA != null){
                            return '<span>'+rowObject.name+'</span>';
                        }

                        for (var i = 0; i <types.length ; i++) {
                            if (rowObject.type==types[i].id){
                                return '<span>'+types[i].name+'</span>'
                            }
                        }

                    }
                    },{
                        name: 'name',
                        index: 'name',
                        width: 20
                    },{
                        name: 'money',
                        index: 'money',
                        width: 10
                    },{
                        name: 'createDate',
                        index: 'createDate',
                        width: 15
                    },{
                        name: 'remark',
                        index: 'remark',
                        width: 35
                    },{
                    name: 'typeA',
                    index: 'typeA',
                    width: 20,
                    formatter:function(cellvalue, options, rowObject){
                        var html = "";

                        if (cellvalue=='1'){
                            html += "<span style='color: red'>类型</span>"
                        }else {
                            html += "<span>物品</span>"
                        }

                        return html;
                    }
                    },
                    {
                    name: 'id',
                    index: 'id',
                    width: 35,
                    formatter:function(cellvalue, options, rowObject){
                        if (rowObject.typeA!=1 ){
                            return  "<a class='btn btn-w-m btn-danger' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"del('"+rowObject.id+"')\">删除</a>";
                        }else {
                            return  "<a class='btn btn-w-m btn-primary' style='font-size: 10px;margin: 3px;padding: 3px;' onclick=\"edit('"+rowObject.id+"')\">修改</a>";
                        }

                    }
                }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: true
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");
            $("#btn-add").click(function(){
            	layer.open({
                    type: 2,
                    title: '添加物品',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['70%', '60%'],
                    content: '${path}/regenerant/add' //iframe的url
                });
            });

            $("#btn-add-type").click(function(){
                layer.open({
                    type: 2,
                    title: '添加类型',
                    shadeClose: false,
                    shade: 0.5,
                    area: ['70%', '60%'],
                    content: '${path}/regenerant/addtype' //iframe的url
                });
            });
            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/regenerant/queryC",
                    datatype:'json',
                    postData : {
                    	"type":$("#type").val(),
                    },
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
        });
        function download(url){

        }

        $("#btn-add-type").click(function(){
            layer.open({
                type: 2,
                title: '添加类型',
                shadeClose: false,
                shade: 0.5,
                area: ['70%', '60%'],
                content: '${path}/regenerant/addtype' //iframe的url
            });
        });

        function edit(id){
            layer.open({
                type: 2,
                title: '修改类型信息',
                shadeClose: false,
                shade: 0.5,
                area: ['70%', '60%'],
                content: '${path}/regenerant/edit?id='+id //iframe的url
            });
        }


        function del(id){
            var op = ("删除");
            layer.confirm("您确定要"+op+"该物品吗? ", {
                btn: ['确定','取消'], //按钮
                shade: true, //不显示遮罩
                shadeClose: true,
                shade: 0.5,
            }, function(){
                console.log("确定")
                $.ajax({
                    type: "POST",
                    url: "${path}/regenerant/del",
                    data:{"id":id},
                    dataType: "json",
                    success: function(json){
                        var code = json.code;
                        if (code==0){
                            layer.msg("删除成功",{icon:1})
                            setTimeout(function(){
                                layer.closeAll();
                                window.location.reload();
                            },1000);
                        }else{
                            layer.msg("删除失败",{icon:5})
                            setTimeout(function(){
                                window.location.reload();
                            },1000);
                        }
                    }

                });
            },function(){
                console.log("取消")

            });


        }

        function down(url,folder) {
            var pfolder = url.split(",");
            var form = $("<form></form>").attr("action", '${path}/qrcode/download').attr("method", "POST");
            form.append($("<input></input>").attr("type", "hidden").attr("name", "pfolder").attr("value", pfolder[0]));
            form.append($("<input></input>").attr("type", "hidden").attr("name", "folder").attr("value", pfolder[1]));
            form.appendTo('body').submit().remove();

        }





    </script>
</body>
</html>
